import React from 'react';
import { routerRedux, Route, Switch } from 'dva/router';
import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import { getRouterData } from './common/router';
import Authorized from './utils/Authorized';
import { getQueryPath } from './utils/utils';

const { ConnectedRouter } = routerRedux;
const { AuthorizedRoute } = Authorized;
function RouterConfig({ history, app }) {
    const routerData = getRouterData(app);
    const UserLayout = routerData['/user'].component;
    const WafLayout = routerData['/'].component;
    const Exception403 = routerData['/exception/403'].component;
    const Exception404 = routerData['/exception/404'].component;
    const Exception500 = routerData['/exception/500'].component;

    return (
        <LocaleProvider locale={zhCN}>
            <ConnectedRouter history={history}>
                <Switch>
                    <Route path="/user" component={UserLayout} />
                    <Route path="/exception/403" component={Exception403} />
                    <Route path="/exception/404" component={Exception404} />
                    <Route path="/exception/500" component={Exception500} />
                    <AuthorizedRoute
                        path="/"
                        authority="1"
                        render={props => <WafLayout {...props} />}
                        redirectPath={getQueryPath('/user/login', {
                            redirect: window.location.href,
                        })}
                    />
                </Switch>
            </ConnectedRouter>
        </LocaleProvider>
    );
}
export default RouterConfig;
